# print(5/0)
# ZeroDivisionError: division by zero 除0错误

# 可用try-except处理可能发生的异常
# try:
#     print(5/0)
# except ZeroDivisionError:
#     print("You can't divide by zero!")

print("Give me two numbersa, and I'll divide them.")
print("Enter 'q' to quit.")

while True:
    first_number = input("\nFirst number: ")
    if first_number == 'q':
        break
    second_number = input("Second number: ")
    if second_number == 'q':
        break
    try:
        answer = int(first_number) / int(second_number)
    except ZeroDivisionError:
        print("You can't divide by zero!")
    else:
        print(answer)
# python尝试执行try中的语句，如果产生except中的错误，就不会执行try中的语句转而执行except中的语句，
# 当try中语句正常执行完后，继续执行else中的语句而跳过except